package com.cloud_notes.demo.common.pojo;


//同一结果返回类
/*
* 属性成员：
* code:状态码表示
* errMsg:处理失败返回的数据信息
* data:业务返回的数据信息
* */

import com.cloud_notes.demo.common.enums.ResultStatusCodeEnum;
import lombok.Data;

@Data
public class Result<T> {
    private int code;//状态码
    private String errMsg;//处理失败返回的信息
    private T data;//业务数据返回信息

    public static <T> Result ok(T data){
        Result<T> result = new Result<>();
        result.setCode(ResultStatusCodeEnum.SUCCESS.getCode());
        result.setErrMsg(null);//成功返回空
        result.setData(data);
        return result;
    }

    private static <T> Result fail(String errMsg,T data){
        Result<T> result = new Result<>();
        result.setCode(ResultStatusCodeEnum.FAIL.getCode());
        result.setErrMsg(errMsg);
        result.setData(null);
        return result;
    }

    public static Result fail(String errMsg) {
        Result result = new Result();
        result.setCode(ResultStatusCodeEnum.FAIL.getCode());
        result.setErrMsg(errMsg);
        return result;
    }
}
